import request from "@/utils/request";

// 登录方法
export function login(username, password, code, uuid) {
  const data = {
    loginId: btoa(encodeURI(username)),
    password: btoa(encodeURI(password)),
    code,
    uuid,
  };
  return request({
    url: "/login",
    method: "post",
    data: data,
  });
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: "/getInfo",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "get",
  });
}

// 退出方法
export function logout() {
  return request({
    url: "/logout",
    method: "post",
  });
}

// 获取验证码
export function getCodeImg() {
  return request({
    url: "/captchaImage",
    method: "get",
  });
}

// 5. 用户设置安全问题
export function setSecurityQuestionAnswer(params) {
  const { dictLabel, password, answer } = params;
  const data = {
    dictLabel,
    password: btoa(encodeURI(password)),
    answer,
  };
  return request({
    url: "/system/user/profile/setSecurityQuestionAnswer",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    params: data,
    method: "POST",
  });
}

// 06、删除一个安全问题
export function deleteSecurityQuestionAnswer(data) {
  // const data = {
  //   dictLabel,
  //   password: btoa(encodeURI(password)),
  // }
  return request({
    url: "/system/user/profile/deleteSecurityQuestionAnswer",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    data: data,
    method: "POST",
  });
}

// 07、清空安全问题
export function clearSecurityQuestionAnswer(password) {
  const data = {
    password: btoa(encodeURI(password)),
  };
  return request({
    url: "/system/user/profile/clearSecurityQuestionAnswer",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    params: data,
    method: "POST",
  });
}

// 08、用户设置是否开启双因子认证
export function settingTwoFactorAuthentication(
  password,
  twoFactorAuthenticationStatus
) {
  const data = {
    password: btoa(encodeURI(password)),
    twoFactorAuthenticationStatus,
  };
  return request({
    url: "/system/user/profile/settingTwoFactorAuthentication",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    params: data,
    method: "POST",
  });
}

// 09、检查用户密码还有多久过期
export function checkExpirationTime() {
  return request({
    url: "/system/user/profile/checkExpirationTime",
    method: "POST",
  });
}

// 登录验证 05、读取安全问题列表
export function getSecurityQuestionList() {
  return request({
    url: "/getSecurityQuestionList",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "GET",
  });
}
// 登录验证 06、验证安全问题
export function verificationSecurityQuestionList(params) {
  return request({
    url: "/verificationSecurityQuestionList",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "GET",
    params: params,
  });
}

// 获取通知内容
export function getLoginNotice() {
  return request({
    url: "/instrument/login/article",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
  });
}
